2012-02-13 1 views
1

다음 샘플 코드가 있습니다. 처음에는 commandButton 두 개의 만 보입니다. 이 단추를 클릭하면 명령 단추도 표시됩니다. 그러나 중 하나를 클릭하면 뒷받침 빈 방법 클릭 1이 실행되지 않습니다.@RequestScoped backing-bean과 함께 숨겨진 commandButton을 사용할 수 없습니다.

XHTML

<h:form id="form1"> 
    <h:inputHidden id="show" value="#{bean.show1}" /> 
    <h:commandButton id="button1" value="One" action="#{bean.click1}" 
     rendered="#{bean.show1}" /> 
</h:form> 
<h:form id="form2"> 
    <h:inputHidden id="show" value="#{bean.show1}" /> 
    <h:commandButton id="button2" value="Two" action="#{bean.click2}" /> 
</h:form> 

백업 콩

@RequestScoped 
@Named("bean") 
public class JsfTrial implements Serializable { 

    private static final long serialVersionUID = 2784462583813130092L; 

    private boolean show1; // + getter, setter 

    public String click1() { 
     System.out.println("Click1()"); 
     return null; 
    } 

    public String click2() { 
     System.out.println("Click2()"); 
     setShow1(true); 
     return null; 
    } 

} 

내가 BalusC하여 매우 유익한 해답을 발견 : 다음

내 코드입니다. 내가 제대로 이해한다면

, 내 문제로 인해 점 (5)이 답변의입니다.

우리는 숨겨진 commandButton을 @RequestScoped backing-bean과 함께 사용할 수 없다는 것을 의미합니까?

답변

6

요청 범위를 사용할 수 있으므로 JSF 숨김 입력 필드 <h:inputHidden> 대신에 <f:param>에 의해 요청 매개 변수로서 조건을 후속 요청에만 전달해야합니다. 숨겨진 입력 필드의 값은 모델 값 업데이트 단계에서 모델에서만 설정되며 rendered 속성의 조건은 이전 요청 값 적용 단계에서 이미 평가됩니다.

그래서, <h:inputHidden> 대신 <f:param>를 사용

<h:form id="form1"> 
    <h:commandButton id="button1" value="One" action="#{bean.click1}" 
     rendered="#{bean.show1}"> 
     <f:param name="show1" value="#{bean.show1}" /> 
    </h:commandButton> 
</h:form> 
<h:form id="form2"> 
    <h:commandButton id="button2" value="Two" action="#{bean.click2}"> 
     <f:param name="show1" value="#{bean.show1}" /> 
    </h:commandButton> 
</h:form> 

이 방법 당신은 빈의 (게시물) 생성자의 요청 매개 변수로를 추출 할 수 있습니다.

public JsfTrial() { 
    String show1 = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("show1"); 
    this.show1 = (show1 != null) && Boolean.valueOf(show1); 
} 

미운하지만 CDI는 JSF의 @ManagedProperty("#{param.show1}") substituties 내장 명령 주석을 제공하지 않습니다. 그러나 homegrow 같은 주석을 사용할 수 있습니다.

+0

귀하의 회신은 너무 좋다 1 !! – Makky

+0

정말 고마워요! 이것은 내가 찾고 있었던 바로 그 것이다. –

+0

반갑습니다. – BalusC

관련 문제