0

ソースコードを含む Visualforce ページを作成します

<apex:page controller="MyController1">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection  id="search">
<apex:commandLink action="{!commandLinkAction}" value="Advance Search"  reRender="thePanel" id="theCommandLink"/>
<apex:outputPanel id="thePanelWrapper">
<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">My div</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

MyController1 クラスは

public class MyController1{
public Boolean rend{get;set;}
public PageReference commandLinkAction(){
rend=true;
return null;
}

}

高度な検索リンクをクリックしても何も起こりませんが、ID「thePanel」のoutputPanelがレンダリングされることを期待していました.なぜレンダリングされないのか誰か説明してください??

4

3 に答える 3

2

ページ上にないパネルのリンクをクリックした瞬間に、SF はそれをレンダリングしませんでした。

于 2013-02-25T04:15:16.167 に答える
1

@Shimshon が言ったように、HTML コードが Visualforce から生成されると、マークされた Visualforce コンポーネントrendered="false"は結果の HTML ドキュメントに表示されません。

この場合:

<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">

このパネルを再レンダリングする場合は、コンポーネントが HTML コードに表示され、再レンダリング アクションがコンポーネントを見つけられるようにする必要があります。コントローラーのコンストラクターで最初に false に設定されているため{! rend}、「thePanel」はページにレンダリングされないため、存在しないコンポーネントを再レンダリングしようとします。

@theGreatDanton のソリューション<apex:outputPanel id="thePanelWrapper">は、常にレンダリングされるコンテナー パネルであるため機能します。

<apex:commandLink action="{!commandLinkAction}" value="Advance Search"  reRender="thePanelWrapper" id="theCommandLink"/>

このパネルが rerender 属性によって指されている場合、「thePanelWrapper」とその子ノード (「thePanel」) が更新されます。

于 2015-04-23T22:42:47.327 に答える
0

以下のコードを試してください。

<apex:page controller="MyController1">
<apex:form>
<apex:pageBlock >
<apex:pageBlockSection  id="search">
<apex:commandLink action="{!commandLinkAction}" value="Advance Search"  reRender="thePanelWrapper" id="theCommandLink"/>
<apex:outputPanel id="thePanelWrapper">
<apex:outputPanel id="thePanel" rendered="{! rend}" layout="block">My div</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

public class MyController1{
   public Boolean rend{get;set;}
   //setting the boolean to false in the constructor
   public MyController1(){
          rend = false;
   }
   public void commandLinkAction(){
      rend=true;
     // return null;
   }

}

お役に立てれば!!

于 2013-02-26T02:37:26.793 に答える