0

我的 xpage 中有 dojo 验证文本框,其中计算了所需的属性(动态计算),如下所示

var syn = getComponent("SynCboxGrp").getValue();
if (syn == "Yes")
{return true;
}else{
    return false;
}

这里组件 SynCboxGrp 是单选按钮。根据单选按钮的值,文本框是必需的。但它不能正常工作。更改单选按钮值不会更改所需的行为。

感谢任何帮助


更新

感谢 stwissel、Per Henrik Lausten 和 Eric。我在必需的属性中只有这个 ssjs

<xe:djValidationTextBox id="UBOCAgent"                      value="#{dsRacDoc.UBOCAgent}"                       disableClientSideValidation="true">
<xe:this.required><![CDATA[#{javascript:var syn = getComponent("SynCboxGrp").getValue();

if (syn == "Yes")
{
    return true;
}else{
    return false;
}
}]]></xe:this.required>
</xe:djValidationTextBox>  

我还在我的单选按钮 onclick 事件上尝试了这个部分刷新代码XSP.partialRefreshGet("#{id:UBOCAgent}");

这仍然不会改变行为。它基于初始单选按钮值工作。不利的一面是,因为它是一个获取请求,它会从服务器更新字段内容。我还尝试了 Eric 的建议禁用客户端验证,但这没有帮助。

Eric,我也在尽可能地使用 CSJS,但在这种情况下,所需的属性只有 SSJS 选项。所以不知道如何尝试 CSJS。我应该尝试创建自己的 dojo 字段而不是使用 entension lib 中的一个吗?如果是这样,我不确定如何计算所需的属性。如果您可以帮助我提供一些示例代码,那将是很大的帮助。谢谢你的时间。

4

2 回答 2

1

You're doing a partialRefreshGet, which is updating the Dojo Validation Text Box. But you never post back the updated value from the radio, so the server-side value for the radio button is still the initial value. Consequently, required is still false.

Check the markup when required is true on the Dojo Validation Text Box, but the validation triggers client-side, so there should be an attribute in the markup that you can manipulate via CSJS, if that is your preferred route.

Do you have particular latency issues that you need to work around? Picking up on this and the other question you have about doing a lookup to a database on click of a button, you're hitting a few problems. I don't know how experienced you are in XPages development, but it's not an approach I would recommend without a good understanding of client-side output and server-side component trees. The initial page load of your XPage will also be slower and the size of the HTML passed to the browser will be larger, because of the amount of CSJS passed to the browser.

I would recommend using the in-built partial refresh except for situations where browser to server network is a significant issue, and only then falling back to coding your own partial refresh posting a subset of data. In my experience, it's easier and quicker to develop, easier to debug and more flexible.

For this particular scenario, regardless of whether you code the partial refresh yourself or use inbuilt functionality, one point I'm not certain of is this. That once you set validation on the Dojo Validation Text Box, that validation runs client-side and may impact any attempt to un-set the required property by posting to the server. I haven't tested, so can't be certain.

于 2012-11-16T23:54:20.607 回答
0

两件事之一:

  1. 如前所述,要触发您的 SSJS 值更改,请确保部分(至少)刷新包含上述代码的元素;可以使用容器元素来完成。此外,检查您的字段的 disableClientSideValidation 参数是否已设置(所有属性视图)。
  2. 将您的 SSJS 代码(仅返回是或其他情况的二进制评估,我假设否,值)转换为 CSJS

最近,在我当前项目的初步开发之后,我开始偏爱 CSJS 方法,以减少服务器端的回调;尤其是在我想要实现的所有组件的显示/渲染的情况下。如果你走这条路,请记住 dojo.byId("#{id:myControlsServerNameHere}").value (对于文本字段,请参阅下面的单选按钮值)结合设置显示可见CSS 属性可能非常便利。正如文档所描述的,如果您希望它存在于页面上但不显示(出于格式化目的,也可以保留默认值),请使用可见性路线,否则显示属性。

我目前正在使用的无线电值的 CSJS 抓取如下:

var result=null;
for(i=0; i<document.forms[0].elements.length;i++){
    if(document.forms[0].elements[i].name=="#{id:serverNameOfRadioElement}"){
        if(document.forms[0].elements[i].checked == true){
            result=document.forms[0].elements[i].value;
            break;
        }
    }
}
//then handle your result, either with an if, or switch statement

希望这可以帮助。如果您遇到更多问题,请回发更多代码以提供更大的图景。

于 2012-11-15T13:46:26.957 回答