기존 JSF 구성 요소를 내 사용자 지정 구성 요소에 추가하는 방법은 무엇입니까?
-
19-08-2019 - |
문제
uicomponent 및 uioutput을 확장하는 태그 클래스가 있습니다. 이 클래스에는 컨텍스트 작가를 사용하여 writer.startelement ( "div", mycomponent) 등을 사용하여 원하는 html 태그를 출력 할 수있는 EncodeBegin 및 Encodeend가 있습니다.
내 문제는 이제 Writer.startElement를 사용하는 대신 a를 삽입해야한다는 것입니다. getchildren (). add (htmlcommandbutton button = new htmlcommandbutton ())을 수행 하여이 작업을 수행 할 수 있습니다. 그러나 그렇게 할 때 나는 write.startelement와 같이 내가 나타나기를 원하는 구성 요소를 출력 할 수없는 것 같습니다.
Richfaces 태그, JSF 태그 및 내 Taglibrary에서 유사한 방법을 활용할 수있는 방법에 대한 좋은 해결책이 있습니까? 간단히 말해서 내가 정말로하고 싶은 것은 내 encodebegin 안에 있습니다.
writer.startElement("a4j:commandButton", myComponent);
writer.writeAttribite("action", "#{Handler.myAction}", null);
writer.endElement("a4j:commandButton");
사전에 감사드립니다
해결책
당신은 사용할 수 없습니다 응답자 당신이 원하는대로. 프로그래밍 방식으로 아동 컨트롤을 추가하는 방법에 대해 생각할 수있는 두 가지 방법은 제본 기인하다 (이 답변을 참조하십시오) 또는 컨트롤이 일반적으로 생성되는 장소 (JSPS에서 태그 클래스).
JSF 구성 요소가 다른 컨트롤을 포함하는 두 가지 방법이 있습니다 : 어린이 또는 지명 된 패싯. 구성 요소는 항상 패싯을 렌더링하는 방법을 제어합니다. 그들이 자녀를 낳으려면 진실로 돌아와야합니다. Getrenderschildren.
이것은 테스트되지 않은 코드이지만 시퀀스는 다음과 같습니다.
@Override
public boolean getRendersChildren() {
return true;
}
@Override
public void encodeBegin(FacesContext context)
throws IOException {
// should really delegate to a renderer, but this is only demo code
ResponseWriter writer = context.getResponseWriter();
writer.startElement("span", this);
String styleClass = getStyleClass();
writer
.writeAttribute("class", styleClass, "styleClass");
UIComponent headerComponent = getFacet("header");
if (headerComponent != null) {
headerComponent.encodeAll(context);
}
writer.startElement("hr", null);
}
@Override
public void encodeChildren(FacesContext context)
throws IOException {
ResponseWriter writer = context.getResponseWriter();
for (UIComponent kid : getChildren()) {
kid.encodeAll(context);
writer.startElement("br", null);
}
}
@Override
public void encodeEnd(FacesContext context)
throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.endElement("span");
}
다른 팁
실제로 대답이 아니라 더 많은 추측이지만 얼굴 컨트롤 중 하나를 확장 할 수 있습니까?
또는 얼굴을 직접 사용하십시오. 이는 직접 사용하지는 않았지만 실제로 원하는 것 같습니다. 또는 html이 나타나고 싶은 곳에 Uioutput 컨트롤을 추가하고 각각의 값을 HTML로 설정할 수 있습니다. 이것이 정확히 F : verbatim이 후드 아래에서하는 일입니다. 그래서 소스 코드를 보는 것 같습니다. )