2011-11-29 2 views
0

JSF 2.0에서 응용 프로그램을 개발 중입니다. 응용 프로그램에는 사용자가 문서 서식 파일을 만들 수있는 페이지가 있어야합니다. Google 문서 양식 기능과 비슷합니다. 예를 들어 사용자는 템플릿에서 inputText, textArea 또는 selectBooleanCheckbox를 원하는 위치를 결정할 수 있어야합니다. 나는 상위 클래스 인 UiDocumentElement와 하위 클래스 인 UiTextarea, UiInputText, ...를 디자인했다.ui에서 다른 ui 태그를 렌더링하는 방법 : repeat

이제 XHTML 페이지에 어떻게 이러한 문서 템플릿을 표시 할 수 있는지 궁금합니다. 내 백업 빈에는 UiDocumentElement 객체가있는 DataModel이 있습니다. 그러나 UI 태그의 다른 유형을 표시하기 위해 UI : 반복을 사용하려면 어떻게해야합니까? 아니면 이것을 달성하기 위해 다른 설계를 시도해야합니까?

사실은이 문제를 해결하기 위해 제공 :

<h1>#{backingBean.templateTitle}</h1> 

<ui:repeat value="#{backingBean.uiDocumentElements}" var="uiElement">   
    <label> 
     <span>#{uiElement.label}</span> 
     <!-- here the application should know whether to render an inputText, an inputTextarea or a selectBooleanCheckbox with the attribute value="#{uiElement.value}" --> 
    </label>   
</ui:repeat> 

어떤 도움을 주시면 감사하겠습니다.

편집 : 관련 질문 링크가있는 BalusC의 의견을 참조하십시오.

+1

관련 : http://stackoverflow.com/questions/3510614/how-to-create-dynamic-jsf- 1-2 형식 필드/3522489 # 3522489 – BalusC

답변

1

가장 쉬운은 3 구성 요소 블록이 rendered 속성을 통해 제어해야하는 것입니다 :

<h:inputText value="#{uiElement.value}" rendered="#{uiElement.type == 'input'}"/> 
<h:inputTextarea value="#{uiElement.value}" rendered="#{uiElement.type == 'textArea'}"/> 
<h:selectBooleanCheckbox value="#{uiElement.value}" rendered="#{uiElement.type == 'checkbox'}"/> 
관련 문제