将命令按钮作为输出文本的一部分

发布于 2025-01-05 22:39:41 字数 3170 浏览 0 评论 0原文

我的列表中有包装器类的对象,在我的 Vf 页面中,我检查包装器的对象是否包含 null,如果它包含 null,则我显示“空闲”,否则显示约会详细信息。

我想要一个按钮创建约会而不是“免费”。

插入按钮代码的正确方法是什么?

<apex:repeat var="slot" value="{!liTimeSlots}">

<tr class="{!IF(ISNULL(slot.sAppointment), 'Free', 'Fill')}">
    <td ><apex:outputText value="{!slot.tstart1}"/></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Patient__c)}"/></td>
        </tr> 
    <tr>
    <td></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), ' ', slot.sAppointmentOverlap.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Patient__c)}"/></td>
        </tr>   

编辑: 在我阅读 mmmix 和 LaceySnr 的答案之前,我使用 css 类来实现。不确定这是否是最好的方法。但现在的问题是控制器方法上没有出现参数值。

<apex:repeat var="slot" value="{!liTimeSlots}">

<tr class="{!IF(ISNULL(slot.sAppointment), 'Free', 'Fill')}">
    <td ><apex:outputText value="{!slot.tstart1}"/></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Patient__c)}"/></td>
      <td><div Class="{!IF(ISNULL(slot.sAppointment), 'ShowButton', 'HideButton')}">
      <apex:commandButton action="{!Book}" Value="Book">
      <apex:param name="Timev" value="{!slot.tstart1}"/></apex:commandButton></div></td>
        </tr> 
    <tr>
    <td></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), ' ', slot.sAppointmentOverlap.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Patient__c)}"/></td>
        </tr>   

public  PageReference Book()
{
String Timeval=ApexPages.CurrentPage().getParameters().get('Timev');
system.debug('timeval +++++++++++++++'+Timeval) ;// This is returning null
pr=Page.Appointment;
pr.setRedirect(true);
pr.getParameters().put('App_start',Timeval);
pr.getParameters().put('App_start_Date',string.valueof(Appointment.Start_Date__c));

return pr;
}

I have objects of wrapper class in a list and in my Vf page i am checking if the object of the wrapper contains null, if it has null then i am displaying 'Free' else displaying the appointment details.

I want to have a button create Appointment instead of 'Free'.

What would the correct way to insert the button code ?

<apex:repeat var="slot" value="{!liTimeSlots}">

<tr class="{!IF(ISNULL(slot.sAppointment), 'Free', 'Fill')}">
    <td ><apex:outputText value="{!slot.tstart1}"/></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Patient__c)}"/></td>
        </tr> 
    <tr>
    <td></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), ' ', slot.sAppointmentOverlap.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Patient__c)}"/></td>
        </tr>   

EDIT :
Before i read the answers from mmmix and LaceySnr i implemented with use of css classes. not sure if this is the best way. But now the issue is of the param value not coming up on the controller method.

<apex:repeat var="slot" value="{!liTimeSlots}">

<tr class="{!IF(ISNULL(slot.sAppointment), 'Free', 'Fill')}">
    <td ><apex:outputText value="{!slot.tstart1}"/></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), '', slot.sAppointment.Patient__c)}"/></td>
      <td><div Class="{!IF(ISNULL(slot.sAppointment), 'ShowButton', 'HideButton')}">
      <apex:commandButton action="{!Book}" Value="Book">
      <apex:param name="Timev" value="{!slot.tstart1}"/></apex:commandButton></div></td>
        </tr> 
    <tr>
    <td></td>

      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), ' ', slot.sAppointmentOverlap.name)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Appointment_Type__c)}"/></td>
      <td><apex:outputText value="{!IF(ISNULL(slot.sAppointmentOverlap), '', slot.sAppointmentOverlap.Patient__c)}"/></td>
        </tr>   

public  PageReference Book()
{
String Timeval=ApexPages.CurrentPage().getParameters().get('Timev');
system.debug('timeval +++++++++++++++'+Timeval) ;// This is returning null
pr=Page.Appointment;
pr.setRedirect(true);
pr.getParameters().put('App_start',Timeval);
pr.getParameters().put('App_start_Date',string.valueof(Appointment.Start_Date__c));

return pr;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

永言不败 2025-01-12 22:39:41

不确定我是否理解有关按钮的事情,但您还有另一种执行 !IF 的方法,例如:

<apex:outputText value="{!field}" rendered="{!condition"} />

如果对于按钮,您正在考虑将 apex:commands 插入中继器并将事件处理程序绑定到特定行,则可以是通过参数完成,

例如,我使用它在每个表行中创建一个comamnd链接:

<apex:column headerValue="Action">
    <apex:commandLink id="cmdDetachService" action="{!detachService}" value="Detach" rerender="mainBlock, errors" status="ajaxPostStatus" >
        <apex:param value="{!item.id}" name="activeService" />
    </apex:commandLink>
</apex:column>

然后在事件处理程序中,您可以从页面参数中提取参数,例如ApexPages.CurrentPage().getParameters().get('activeService')

另外,如果您想在 td 标记内呈现 if/then/else 文本/按钮,您可以使用此

<td>
    <apex:outputText .... rendered="{!condition"} />
    <apex:commandButton .... rendered="{!NOT(condition)"} />
</td>

Not sure I understand the thing about the button, but you also have an alternative way of doing !IF, for example:

<apex:outputText value="{!field}" rendered="{!condition"} />

If for button you are thinking about inserting apex:commands into a repeater and tie event handler to specific row, that can be done through parameters

for example I used this to crete a comamnd link in every table row:

<apex:column headerValue="Action">
    <apex:commandLink id="cmdDetachService" action="{!detachService}" value="Detach" rerender="mainBlock, errors" status="ajaxPostStatus" >
        <apex:param value="{!item.id}" name="activeService" />
    </apex:commandLink>
</apex:column>

Then in the event handler you can extract parameter from page parameters, for example ApexPages.CurrentPage().getParameters().get('activeService')

Also, if you want to have if/then/else text/button rendering inside a td tag you can use this

<td>
    <apex:outputText .... rendered="{!condition"} />
    <apex:commandButton .... rendered="{!NOT(condition)"} />
</td>
厌倦 2025-01-12 22:39:41

我建议使用另一种机制来控制条件渲染。 对此效果很好,尽管没有专门为此目的而设计,例如,您可以将:更改

<td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.name)}"/></td>

为:

<apex:variable var="v" value="" rendered="{!IF(ISNULL(slot.sAppointment), true, false)}">
    <td><apex:commandButton action="{!someAction} value="Do This!"/></td>
</apex:variable>
<apex:variable var="v" value="" rendered="{!IF(ISNULL(slot.sAppointment), false, true)}">
    <td><apex:outputText value="{!slot.sAppointment.name}"/></td>
</apex:variable>

显然在这种情况下它生成了更多代码,但看看其余的代码我认为您可以(根据上下文)进一步将其归结为仅使用其中几个标签和更少的 rendered 属性。

I'd suggest just using another mechanism for controlling the conditional rendering. <apex:variable> works well for this despite not being expressly designed for this purpose, for example, you could change:

<td><apex:outputText value="{!IF(ISNULL(slot.sAppointment), 'Free', slot.sAppointment.name)}"/></td>

to:

<apex:variable var="v" value="" rendered="{!IF(ISNULL(slot.sAppointment), true, false)}">
    <td><apex:commandButton action="{!someAction} value="Do This!"/></td>
</apex:variable>
<apex:variable var="v" value="" rendered="{!IF(ISNULL(slot.sAppointment), false, true)}">
    <td><apex:outputText value="{!slot.sAppointment.name}"/></td>
</apex:variable>

Obviously in this case it's generated more code, but looking at the rest of this I think you could (with context) boil this down further to use just a couple of these tags and fewer rendered attributes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文