小编Zac*_*ese的帖子

JSF 2本地化(托管bean)

我有一个用于本地化的属性文件:

foo=Bar
title=Widget Application
Run Code Online (Sandbox Code Playgroud)

这与resource-bundlefaces-config中的a相关:

<resource-bundle>
    <base-name>com.example.messages.messages</base-name>
    <var>msgs</var>
</resource-bundle>
Run Code Online (Sandbox Code Playgroud)

我可以使用EL在facelets视图中访问它:

<title>#{msgs.title}</title>
Run Code Online (Sandbox Code Playgroud)

但是,如果有像SQLExceptions这样的东西,我需要能够从托管bean编写消息.这一切都有效:

FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "There was an error saving this widget.", null);
FacesContext.getCurrentInstance().addMessage(null, message);
Run Code Online (Sandbox Code Playgroud)

这是问题所在:我希望这些消息来自属性文件,以便它们也可以根据区域设置进行更改.有没有一种简单的方法来使用注入访问属性文件?

jsf cdi jsf-2 managed-bean

7
推荐指数
1
解决办法
2万
查看次数

对于h:commandLink,使用f:attribute为commandButton而不是f:param

我想根据点击的按钮包含特定页面.

到目前为止h:commandButton,我无法使用f:param,所以看起来我应该使用f:attribute标签.

如果f:param我会像这样编码:

<h:commandLink action="connectedFilein">
    <f:param name="fileId" value="#{fileRecord.fileId}"/>
<h:commandLink>

<c:if test="#{requestParameters.fileId!=null}">
    <ui:include src="fileOut.xhtml" id="searchOutResults"/>
</c:if>
Run Code Online (Sandbox Code Playgroud)

怎么f:attribuite回事?

谢谢

parameters jsf command button hyperlink

7
推荐指数
1
解决办法
3万
查看次数

Android中的IP回退

我正在访问服务器以进行Web服务调用.当我在与服务器相同的网络上进行开发时,我可以通过其内部IP地址访问Web服务,但不能访问其外部IP地址.但是,如果我不在网络上,我只能通过其外部IP地址访问它.尝试其中一个IP地址然后再回到另一个IP地址的最佳方法是什么?

这是我的代码示例,仅用于访问其中一个或另一个:

protected String retrieve() {
    Log.v(TAG, "retrieving data from url: " + getURL());

    HttpPost request = new HttpPost(getURL());
    try {
        StringEntity body = new StringEntity(getBody());
        body.setContentType(APPLICATION_XML_CONTENT_TYPE);
        request.setEntity(body);            

        HttpConnectionParams.setConnectionTimeout(client.getParams(), CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_TIMEOUT);

        HttpResponse response = client.execute(request);
        final int statusCode = response.getStatusLine().getStatusCode();


        if (statusCode != HttpStatus.SC_OK) {
            Log.e(TAG, "the URL " + getURL() + " returned the status code: " + statusCode + ".");
            return null;
        }

        HttpEntity getResponseEntity = response.getEntity();

        if (getResponseEntity != null) {
            return EntityUtils.toString(getResponseEntity);
        }
    } catch …
Run Code Online (Sandbox Code Playgroud)

java ip android web-services apache-commons

7
推荐指数
1
解决办法
478
查看次数

JSF2:将 cc:attribute 限制为列表中的给定对象类型

如果我有一个托管 bean,如下所示:

@ManagedBean
@RequestSchoped
public class Example {

    private List<String> stringList;
    private List<Long> longList;

    // getters, setters, etc. down here
}
Run Code Online (Sandbox Code Playgroud)

并且有一个接受 List 作为属性的自定义组件:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:cc="http://java.sun.com/jsf/composite"
      xmlns:h="http://java.sun.com/jsf/html">

  <!-- INTERFACE -->
  <cc:interface>
      <cc:attribute name="aList" type="java.util.List" />
  </cc:interface>

  <cc:implementation>
      <!-- code is in here -->
  </cc:implementation>
</html>
Run Code Online (Sandbox Code Playgroud)

我怎么能确保这有效:

<myComp:previousComponent aList="#{example.stringList}" />
Run Code Online (Sandbox Code Playgroud)

但这没有:

<myComp:previousComponent aList="#{example.longList}" />
Run Code Online (Sandbox Code Playgroud)

换句话说,我想做的事情cc:attribute如下:

<cc:attribute name="aList" type="java.util.List<java.lang.String>" />
Run Code Online (Sandbox Code Playgroud)

然而,正如我们所知,xhtml 不喜欢使用 > 或 <。此外,由于仅在编译时检查泛型,我不确定这将如何完成。有谁知道这是否可能?

xhtml jsf facelets composite-component jsf-2

6
推荐指数
1
解决办法
6685
查看次数

什么决定JSF版本?容器或面部配置?

我目前正在JBoss AS 4.3上运行一个旧的JSF应用程序.我相信这实现了JSF 1.2.但是,当我查看faces-config时,我发现它使用的是JSF 1.1 DTD.

我使用的是哪个版本的JSF?

xml jsf jsf-1.2 jboss-eap-4.3.x

6
推荐指数
1
解决办法
4961
查看次数

JSF2复合组件为action方法抛出PropertyNotFoundException

我有一个复合组件:

<composite:interface>
    <composite:attribute name="actionMethod" 
        method-signature="java.lang.String action()" required="true" />
</composite:interface>

<composite:implementation>
    <h:form>
        <h:commandButton id="captureButton" value="#{msgs.capture}" 
            action="#{cc.attrs.actionMethod}" />
    </h:form>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

和一个调用该复合组件的页面:

<ezcomp:captureTitle actionMethod="#{saveDecisionsBean.captureTitle}" />
Run Code Online (Sandbox Code Playgroud)

和一个包含动作的bean:

@Named(value="saveDecisionsBean")
@SessionScoped
public class SaveDecisionsBean extends BackingBeanBase {
    ...
    public String captureTitle() {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

现在这是我的问题.当我尝试运行它时,它说SaveDecisionsBean没有属性captureTitle.因此,我必须添加一个SaveDecisionsBean#getCaptureTitle()方法.当我这样做时,它运行得很好.我为什么要定义这个方法?它说它<composite:attribute />是一种方法,它被用作一种动作.

这是我得到的确切错误消息:

javax.el.PropertyNotFoundException: /index.xhtml @54,86 
    actionMethod="#{saveDecisionsBean.captureTitle}": 
    The class 'com.example.persistence.SaveDecisionsBean_$$_javassist_209'
    does not have the property 'captureTitle'.
Run Code Online (Sandbox Code Playgroud)

(出于SEO原因:其他实现可能会显示类名WeldClientProxy.)

jsf composite-component jsf-2

4
推荐指数
1
解决办法
8353
查看次数

ruby string concatenation(我想?)

我刚刚开始使用"The Well-Grounded Rubyist",他们给出了以下示例:

print "Hello. Please enter a Celsius value: "
print "The Fahrenheit equivalent is ", gets.to_i * 9 / 5 + 32, ".\n"
Run Code Online (Sandbox Code Playgroud)

特别是,我正在看第2行,他们似乎在使用逗号进行字符串连接.我假设+因为+ 32代码的一部分而没有使用该符号.但是,有人可以向我解释一下逗号究竟在做什么吗?

ruby string string-concatenation

1
推荐指数
1
解决办法
441
查看次数

检测泛型中的泛型类型

我有一个接受许多不同类型的对象进行存储的方法:

public void Store<T>(T item)
{
    // works fine
    if (item is Foo)
    {
      // ...
    }
    // works fine
    else if (item is Observation<ImageSignal>)
    {
      // ...
    }

    // isn't detected
    else if (item is Observation<Signal<ISpectrum>>)
    {
      // ...
    }

    else 
    {
      // Observation<Signal<ISpectrum>> always hits this.
      throw new NotSupportedException();
    }
}
Run Code Online (Sandbox Code Playgroud)

谁能告诉我怎么能发现这个?

编辑: 我实际上传递了一个包裹这个对象的对象.埃里克是对的.问题解决了.但是,感谢您的快速反应.

c#

1
推荐指数
1
解决办法
67
查看次数